/*
 * PrjNewTab.java
 *
 * Created on September 5, 2007, 11:25 PM
 *            October 2009: The tree nodes names, useds to identify mouse clicks into mouseRelesase method, were changed from hard code, to the use of getName class Method.
 *            2, February 2010: This class and DBTreeTreeTab are now on aligned, in order to allow to aply to them Patterns.
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package portfolio.dbHost;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import portfolio.dbHost.project.Project;
import portfolio.dbHost.project.attributes.ExcludeColumns;
import portfolio.dbHost.project.attributes.ExcludeTables;
import portfolio.dbHost.project.attributes.InputAttribs;
import portfolio.dbHost.project.attributes.OptionalAttributes;
import portfolio.dbHost.project.attributes.StockExperiments;
import portfolio.dbHost.project.attributes.TimeLine;
import portfolio.dbHost.project.attributes.experiments.Experiment;
import portfolio.mainScreen;

/**
 *
 * @author ACA
 */
public class ProjectTreeTab extends TreeTab
{
    JPanel jTreePanel = null;
    
    /** Creates a new instance of PrjNewTab */
    public ProjectTreeTab (JPanel jTreePanelParam) throws Exception
    {
        jTreePanel = jTreePanelParam;
        if (jTreePanel == null)
            throw new Exception ("No jTreePanel provided.");

        jTreePanel.setLayout(new BorderLayout ());
    }
    /**
     * 
     * @param projectParam
     */
    public void initComponents (Project projectParam)
    {
        try {
            treeObject = projectParam;
            if (treeObject == null)
                throw new Exception ("No projet provided.");
            
            mainFrame = this.getMainScreen(treeObject);

            DefaultMutableTreeNode root = this.getMutableTreeNode (treeObject);

            visibleTree = new JTree(root);
            visibleTree.addMouseListener(this);

            JScrollPane scrollTree = new JScrollPane ();
            scrollTree.getViewport ().add (visibleTree);

            jTreePanel.add(scrollTree, BorderLayout.CENTER);
        } catch (Exception ex) {
            mainFrame.displayMessage("PrNewTab.PrNewTab 89", ex.toString());
        }            
    }

    mainScreen getMainScreen(Object treeObject) {
        return ((Project) treeObject).getProjectDBase().getDBHost().getMainScreen();
    }

    DefaultMutableTreeNode getMutableTreeNode(Object treeObject) {
        return ((Project) treeObject).processProjectHierarchy();
    }

    Object getTreeObject(Object[] objectPath) {
        return ((Project) treeObject).getTreeObject(objectPath);
    }
    /**
     *
     */
    void getClassPopupOption (Object oPopup, int iXPos, int iYPos)
    {
        try {
            String sClassName = oPopup.getClass().getName();

            if (sClassName.equals (Project.class.getName())) {
                ((Project)            oPopup).getPopupOptions (visibleTree, iXPos, iYPos);
            } else if (sClassName.equals (InputAttribs.class.getName())) {
                ((InputAttribs)       oPopup).getPopupOptions (visibleTree, iXPos, iYPos);
            } else if (sClassName.equals (ExcludeTables.class.getName())) {
                ((ExcludeTables)      oPopup).getPopupOptions (visibleTree, iXPos, iYPos);
            } else if (sClassName.equals (ExcludeColumns.class.getName())) {
                ((ExcludeColumns)     oPopup).getPopupOptions (visibleTree, iXPos, iYPos);
            } else if (sClassName.equals (TimeLine.class.getName())) {
                ((TimeLine)           oPopup).getPopupOptions (visibleTree, iXPos, iYPos);
            } else if (sClassName.equals (StockExperiments.class.getName())) {
                ((StockExperiments)   oPopup).getPopupOptions (visibleTree, iXPos, iYPos);
            } else if (sClassName.equals (Experiment.class.getName ())) {
                ((Experiment)         oPopup).getPopupOptions (visibleTree, iXPos, iYPos);
            } else if (sClassName.equals (OptionalAttributes.class.getName ())) {
                ((OptionalAttributes) oPopup).getPopupOptions (visibleTree, iXPos, iYPos);
            } else {
                mainFrame.displayMessage("DBTreeTab.mouseReleased 90", "error at jDBaseTree.");
            }
        } catch (Exception ex) {
            String sClassName = this.getClass().getName ();
/*0j0*/     mainFrame.displayMessage(sClassName + " 84", ex.toString());
        }
    }
}
